package com.cqs.leetcode.hash;

/**
 * @author lixiaowen
 * @create 2019-12-11
 */
public class FirstUniqueCharacterinaString387 {

    public int firstUniqChar(String s) {
        if(s == null || s.length() == 0) return -1;
        char[] cs = s.toCharArray();
        char[] letters = new char[26];
        for (int i = 0; i < cs.length; i++) {
            letters[cs[i]-'a']++;
        }

        for (int i = 0; i < cs.length; i++) {
            if (letters[cs[i] - 'a'] == 1) {
                return i;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        FirstUniqueCharacterinaString387 f = new FirstUniqueCharacterinaString387();
        String[] s = {"loveleetcode","leetcode","","hdsadaslkdf1fddsafh","dddccdbba"        };
        for (String s1 : s) {
            System.out.println(f.firstUniqChar(s1));
        }

    }
}
